package com.shiliao.app.activity.personal.ui;

import android.content.Intent;
import android.text.InputType;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.shiliao.app.R;
import com.shiliao.app.activity.personal.presenter.SeetingInfoPresenter;
import com.shiliao.app.activity.personal.view.SeetingInView;
import com.shiliao.app.manager.YMUserManager;
import com.shiliao.app.utils.FileNameManage;
import com.shiliao.app.weight.ActionBarView;
import com.yimei.framework.base.ui.BaseActivity;
import com.yimei.framework.util.PreferenceHelper;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by yinzhiqiang on 2017/9/13.
 */

public class SeetingInfoActivity extends BaseActivity implements SeetingInView {

    @BindView(R.id.ac_bar)
    ActionBarView mActionBar;

    @BindView(R.id.et_nick_name)
    EditText mNickName;

    @BindView(R.id.et_phone)
    EditText et_phone;

    @BindView(R.id.et_weixin_nm)
    EditText et_weixin_nm;

    @BindView(R.id.tv_type_name)
    TextView mTypeNmae;
    private String from;
    private String nick;
    private String phoneNumber;
//    private String getEditText;//获取输入框的内容
    private String weixinNum;
    private SeetingInfoPresenter seetingInfoPresenter;

    @Override
    public int getLayoutId() {
        return R.layout.activity_seetinginfo;
    }

    @Override
    public void initView() {
        super.initView();
        mActionBar.setBackClick(this);
        mActionBar.getBackView().setVisibility(View.VISIBLE);
        nick = PreferenceHelper.readString(this, FileNameManage.PERSONAL_PAGE,
                FileNameManage.PERSONAL_USER_NICK);//存储用户nick
        phoneNumber = PreferenceHelper.readString(this, FileNameManage.PERSONAL_PAGE,
                FileNameManage.PERSONAL_USER_PHONE_NM);//存储用户手机号码

        weixinNum = PreferenceHelper.readString(this, FileNameManage.PERSONAL_PAGE,
                FileNameManage.PERSONAL_USER_WEIXIN_NM);//存储用户WEIXIN号

        mActionBar.setTitles("设置个人信息");

        if (!TextUtils.isEmpty(nick)){
            mNickName.setText(nick);
        }
        if (!TextUtils.isEmpty(phoneNumber)){
            et_phone.setText(phoneNumber);
        }
        if (!TextUtils.isEmpty(weixinNum)){
            et_weixin_nm.setText(weixinNum);
        }
        seetingInfoPresenter = new SeetingInfoPresenter(this);
    }


    @Override
    public String getUserId() {
        return YMUserManager.getUserId(this);
    }


    @Override
    public void toast(final String message) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                showToast(message);
            }
        });
    }

    @Override
    public void closePage() {//设置成功,关闭页面
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                finish();
            }
        });

    }

    @OnClick(R.id.tv_save_info)
    public void setInfo() {
       String nickName = mNickName.getText().toString().trim();
       String phoneNum=et_phone.getText().toString().trim();
       String weixin=et_weixin_nm.getText().toString().trim();
       if (TextUtils.isEmpty(nickName)){
           showToast("请设置昵称");
           return;
       }
       if (!TextUtils.isEmpty(phoneNum)){
           if (phoneNum.length()!=11){
               showToast("请输入正确的手机号码");
               return;
           }
       }
        seetingInfoPresenter.request(nickName, phoneNum,weixin);
    }
}
